package com.hmsg.health.dao;


import com.hmsg.health.bean.Dto.SorderDto;
import com.hmsg.health.bean.domain.SorderDo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface AdminSorderDao {


    @Select("<script>" +
            " select s.* from s_order  s left join s_user u on s.user_id =u.id" +
            "   where 1=1  " +
            "    <if test='phone != null '>" +
            "     and u.mobile=#{phone} " +
            "    </if>" +
            "    <if test='time != null '>" +
            "   and  DATE_FORMAT(s.pay_time, '%Y-%m-%d') = DATE_FORMAT(#{time},'%Y-%m-%d') " +
            "    </if>" +
            "  order by s.id desc"+
            "  limit #{firstResult},#{maxResult}"+

            "</script>")
    List<SorderDto> findAll(@Param("phone") String phone,
                            @Param("time") String time,
                            @Param("firstResult") Integer firstResult,
                            @Param("maxResult") Integer maxResult);

    @Select("<script>" +
            " select count(s.id) from s_order  s left join s_user u on s.user_id =u.id" +
            "   where 1=1  " +
            "    <if test='phone != null '>" +
            "     and u.mobile=#{phone} " +
            "    </if>" +
            "    <if test='time != null '>" +
            "   and  DATE_FORMAT(s.pay_time, '%Y-%m-%d') = DATE_FORMAT(#{time},'%Y-%m-%d') " +
            "    </if>" +
            "</script>")
    int countAll(@Param("phone") String phone, @Param("time") String time);
}
